package com.sduept.nwld.dataserver.manager.protection;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sduept.core.dao.SuperDAO;
import com.sduept.nwld.dataserver.model.daily.OperationaRiskExceed;
import com.sduept.generator.ObjectId;

@Service
public class OperationRiskExceedManager {
	@Autowired
	SuperDAO dao;

	public List<OperationaRiskExceed> getSumExceedList(String start, String end) {
		List<OperationaRiskExceed> exceed = new ArrayList<OperationaRiskExceed>();
		OperationaRiskExceed p = new OperationaRiskExceed();
		Integer dir = 0;
		Integer guangdong = 0;
		Integer guangxi = 0;
		Integer guizhou = 0;
		Integer hainan = 0;
		Integer yunnan = 0;
		end = end.replace("00:00:00", "23:59:59");
		String sql = "select sum(directTransferNum) as directTransferNum,sum(GuangDongNum) as GuangDongNum,sum(GuangXiNum) as GuangXiNum"
				+ ",sum(GuiZhouNum) as GuiZhouNum,sum(HaiNanNum) as HaiNanNum,sum(yunnanNum) as yunnanNum"
				+ " from t_daily_protectrisk_exceed where recordDate between '"
				+ start
				+ "' and '"
				+ end
				+ "'";
		List<?> obs = dao.nativeQuery(sql);
		for (Object o : obs) {
			Object[] os = (Object[]) o;
			if (os[0] != null) {
				dir = ((BigDecimal) os[0]).intValue();
				guangdong = ((BigDecimal) os[1]).intValue();
				guangxi = ((BigDecimal) os[2]).intValue();
				guizhou = ((BigDecimal) os[3]).intValue();
				hainan = ((BigDecimal) os[4]).intValue();
				yunnan = ((BigDecimal) os[5]).intValue();
			}
			p.setDirectTransferNum(dir);
			p.setGuangdongNum(guangdong);
			p.setGuangxiNum(guangxi);
			p.setGuizhouNum(guizhou);
			p.setHainanNum(hainan);
			p.setYunnanNum(yunnan);
			String id = p.getId();
			if (id == null || id.trim().length() == 0) {
				id = ObjectId.get().toString();
			}
			p.setId(id);
		}
		exceed.add(p);
		return exceed;
	}
	
	public List<OperationaRiskExceed> findAll(){
		return dao.findAll(OperationaRiskExceed.class);
	}
	
	public void updateRiskExceed (OperationaRiskExceed select){
		dao.update(select, OperationaRiskExceed.class);
	}
}
